#pragma once

#include "IRenderAPI.h"
#include "Modules.h"


struct IShaderManager;

class CDirectX9: public IRenderAPI
{
public:
	CDirectX9();
	virtual ~CDirectX9();

	//	IRenderAPI
	virtual bool Init();

	virtual IShader* CreateShader(const char* name);

	virtual ITexture* CreateTexture(uint width, uint height, uint levels, ETextureFormat format, bool dynamic);
	virtual ITexture* CreateTexture(const char* filepath, uint width, uint height, uint levels, ETextureFormat format, bool dynamic);


	virtual IIndexBuffer* CreateIndexBuffer(uint length, bool dynamic);
	virtual IVertexBuffer* CreateVertexBuffer(uint length, bool dynamic);

	virtual void StartRendering();
	virtual void FinishRendering();
	virtual void SwapBuffers();

	virtual void ClearBuffer(uint flags, const Color& color, float z);
	virtual void SetShader(IShader* pShader);
	virtual void SetTexture(ITexture* pTexture);
	virtual void DrawPrimitives(EPrimitiveType ptype, const IVertexBuffer* vertices, uint16 vertex_count,	const IIndexBuffer* indices, uint16 index_count);
	//	---

private:
	void InitVertexDeclaration();
	bool IsRenderingStarted() const;

private:
	IDirect3D9*										m_pD3D;
	IDirect3DDevice9*							m_pDevice;
	IDirect3DVertexDeclaration9*	m_pVertexDeclaration;

	IShader*					m_pShader;
	IShaderManager*		m_pShaderManager;

	bool							m_bRendering;	//	application can do rendering
};

REGISTER_RENDER_API_MODULE(CDirectX9);